package com.sh.controller;

import com.sh.pojo.Article;
import com.sh.pojo.ArticlePageDto;
import com.sh.pojo.PageBean;
import com.sh.pojo.Result;
import com.sh.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @PostMapping
    public Result add(@RequestBody Article article){
        log.info("文章信息：{}"+article);
        articleService.add(article);
        return Result.success();
    }
    @GetMapping
    public Result<PageBean> list(ArticlePageDto articlePageDto){
        PageBean<Article>list=articleService.list(articlePageDto);
        return Result.success(list);
    }
    @GetMapping("detail")
    public Result<Article> detail(Integer id){
        Article article=articleService.detail(id);
        return Result.success(article);
    }
    @PutMapping
    public Result update(@RequestBody Article article){
        articleService.update(article);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer id){
        articleService.delete(id);
        return Result.success();
    }
}
